-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parser Performance Collection #9348
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9816/ |
Really nice! Please let us know when it's ready for review. |
This also fixes a bug with async functions
Fix plugin options
This avoids checking isIdentifierStart for every single token
This saves some steps, as the regex parser does not have to backtrack for character classes, but is has to for alternates
It does a lot of checks and a regex test
Instead of calling isKeyword we simple check directly if the keyword token is available
I'm done now. Added some more changes, especially the keyword change brings some performance. |
|
||
switch (env) { | ||
// Configs used during bundling builds. | ||
case "babel-parser": | ||
convertESM = false; | ||
ignoreLib = false; | ||
envOpts.targets = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible we didn't add this before since Babylon was in another repo and a different config? Or I think it was actually slower before? Or it was because of browser support..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great changes, yeah object -> map/set is good
There was a reason for the parser thing but it's probably browser compat
} | ||
|
||
getPluginOption(plugin: string, name: string) { | ||
if (this.hasPlugin(plugin)) return this.plugins[plugin][name]; | ||
// $FlowIssue | ||
if (this.hasPlugin(plugin)) return this.plugins.get(plugin)[name]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just out of curiosity, what does flow complain about here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is because of this: facebook/flow#2751
Flow does not realize that calling has
ensures that get
will return something !=null
Other way would be just calling get and testing if != null
.
@@ -1630,7 +1631,7 @@ export default (superClass: Class<Parser>): Class<Parser> => | |||
this.match(tt.name) && | |||
(this.state.value === "type" || | |||
this.state.value === "interface" || | |||
this.state.value == "opaque") | |||
this.state.value === "opaque") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should enable the eslint rule to only allow ==
for null/undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
The changes in this PR introduced a regression, see #9374. |
So I tried to work on performance in the parser. I did not have any ground breaking success but found some small and minor stuff here and there.
Some of the changes might be debatable. If something feels weird to any of you feel free to mention and I can remove it.
The most impactful change here (depending on the tested source of course) is the removal of flow code from the regular parser. (Only if not using the flow plugin)
The other big improvement is compiling the parser for node 6.9 or newer only. I was surprised to see it was using all transforms. This might be a problem if someone is using the parser in an older browser without first compiling.
Overall it is a tiny bit noticeable but most changes also add to readability and understanding the code.
The changes are separated into commits to make it easier to see what belongs together.
I also tried other things like exchanging the big switch-case for an object as hashmap, but that made no difference.
I also updated the benchmark tool to work better and more consistently. babel/parser_performance@1df708c